home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / internet-tools / nntpkick13 / c / nntppost next >
Encoding:
Text File  |  1996-02-26  |  2.9 KB  |  114 lines

  1. /*
  2.  */
  3.  
  4. sitefile="UULIB:sitename"                           /* Holds full sitename */
  5. mqueue="TCPIP:Spool/Mqueue/"                        /* Must end in slash   */
  6. nqueue="TCPIP:Spool/Nqueue/"                        /* Must end in slash   */
  7. batchfile="UUSPOOL:batch/demon"                     /* List of postings    */
  8. tempfile="T:NNTPPost-Temp"                          /* Tempory work file   */
  9.  
  10. /* Format of the files in the Nqueue directory are as follows...
  11.  *
  12.  * <seq>.txt   contains the header and body of the message
  13.  * <seq>.wrk   contains the information for NNTP
  14.  *
  15.  * A typical entry for <seq>.wrk would look like this...
  16.  *
  17.  * <1> <dan.0001@blender.demon.co.uk>   <article's message id>
  18.  */
  19.  
  20. if open(batchfile,batchfile,"r")==0 then
  21.   exit 0
  22.  
  23. sitename=""
  24. if exists("UUCP:sitename") then
  25.   sitefile="UUCP:sitename"
  26. if open(sitefile,sitefile,"r")==1 then do
  27.   sitename=readln(sitefile)
  28.   close(sitefile)
  29. end
  30. if sitename=="" then do
  31.   say "Couldn't open UULIB:sitename or UUCP:sitename for reading"
  32.   exit 20
  33. end
  34.  
  35. seqfile=mqueue||"sequence.seq"
  36. if open(seqfile,seqfile,"r")==0 then
  37.   sequence=1
  38. else do
  39.   sequence=""
  40.   sequence=readln(seqfile)
  41.   if sequence=="" then
  42.     sequence=1
  43.   close(seqfile)
  44. end
  45.  
  46. do forever
  47.   article=readln(batchfile)
  48.   if eof(batchfile) then
  49.     leave
  50.  
  51.   sequence=sequence+1
  52.   say "Processing sequence" sequence||"..."
  53.  
  54.   article="UUNEWS:"||translate(article,"/",".")
  55.   if open(article,article,"r")==0 then do
  56.     say "Couldn't open" article "for reading"
  57.     sequence=sequence-1
  58.     iterate
  59.   end
  60.  
  61.   lckfile=nqueue||sequence||".lck"
  62.   address command "echo >"||lckfile
  63.  
  64.   txtfile=nqueue||sequence||".txt"
  65.   if open(txtfile,txtfile,"w")==0 then do
  66.     say "Couldn't open" article||"'s file" txtfile "for writing"
  67.     sequence=sequence-1
  68.     close(article)
  69.     address command "delete >nil:" lckfile
  70.     iterate
  71.   end
  72.  
  73.   headlines=0
  74.   do forever
  75.     string=readln(article)
  76.     headlines=headlines+1
  77.     if string=="" then
  78.       leave
  79.     else if upper(left(string,12))=="MESSAGE-ID: " then
  80.       messageid=string
  81.     else if left(string,6)=="Path: " then
  82.       string="Path:" sitename||"!"||substr(string,7)
  83.     writeln(txtfile,string)
  84.   end
  85.   close(txtfile)
  86.   close(article)
  87.   address command "tail +"||headlines-1 article ">>"||txtfile
  88.  
  89.   wrkfile=nqueue||sequence||".wrk"
  90.   if open(wrkfile,wrkfile,"w")==0 then do
  91.     say "Couldn't open" article||"'s file" wrkfile "for writing"
  92.     sequence=sequence-1
  93.     address command "delete >nil:" txtfile
  94.     address command "delete >nil:" lckfile
  95.     iterate
  96.   end
  97.   writeln(wrkfile,substr(messageid,13))
  98.   close(wrkfile)
  99.  
  100.   address command "delete >nil:" lckfile
  101. end
  102. close(batchfile)
  103.  
  104. address command "delete >nil:" tempfile
  105. address command "delete >nil:" batchfile||".done"
  106. address command "rename >nil:" batchfile batchfile||".done"
  107.  
  108. if open(seqfile,seqfile,"w")==0 then do
  109.   say "Couldn't open" seqfile "for a rewrite - it should be" sequence
  110.   exit 20
  111. end
  112. writeln(seqfile,sequence)
  113. close(seqfile)
  114.